import Channels from "../../components/channels";
import './Filter.less'
import {Button, Form, Radio,DatePicker} from "antd";
import {useDispatch} from "react-redux";
import {editFilter} from "../../store/filter";
const { RangePicker } = DatePicker;



function Filter(props) {
    const dispatch=useDispatch()
    const onFinish = (values) => {
        const {status,channel_id,pubdate}=values
        // console.log('Success:', values);
        const qureyData={
            status:status===-1?null:status,
            channel_id,
            begin_pubdate:pubdate?pubdate[0].format('YYYY-MM-DD+HH:mm:ss'):null,
            end_pabdate:pubdate?pubdate[1].format('YYYY-MM-DD+HH:mm:ss'):null
        }
        //启动筛选
        dispatch(editFilter({type:true,info:qureyData}))
        console.log(qureyData)
    };
    return (
        <div className='filter_box'>
            <Form
                name="basic"
                labelCol={{ span: 2 }}
                labelWrap
                initialValues={{status:-1}}
                onFinish={onFinish}
            >
                {/*状态*/}
                <Form.Item name="status" label='状态'>
                    <Radio.Group>
                        <Radio value={-1}>全部</Radio>
                        <Radio value={0}>草稿</Radio>
                        <Radio value={1}>待审核</Radio>
                        <Radio value={2}>审核通</Radio>
                        <Radio value={3}>审核失败</Radio>
                    </Radio.Group>
                </Form.Item>
                {/* 频道 */}
                <Form.Item name="channel_id" label="频道" className='channel'>
                    <Channels/>
                </Form.Item>
                {/*日期*/}
                <Form.Item
                name='pubdate'
                label='日期'
                >
                    <RangePicker />
                </Form.Item>
                {/*按钮*/}
                <Form.Item wrapperCol={{ offset: 1 }}>
                    <Button type="primary" htmlType="submit">
                        筛选
                    </Button>
                </Form.Item>
            </Form>
        </div>
    );
}

export default Filter;
